package com.ayf.payment.game.api.controller;

import com.ayf.payment.game.api.dto.MerchantDTO;
import com.ayf.payment.game.api.dto.ReissueAllDTO;
import com.ayf.payment.game.api.dto.criteria.ReissueAllCriteria;
import com.ayf.payment.game.api.entity.ReissueAllTask;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.service.ReissueAllTaskService;
import com.ayf.payment.game.api.type.CommonConstants;
import com.ayf.payment.game.api.utils.CommonResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 整区补发控制层
 * @Author: zh-liang
 * @Date : 2019-12-26 11:28
 */
@RestController
@RequestMapping("/v/reissueAll")
public class ReissueAllTaskController {
    @Autowired
    private ReissueAllTaskService reissueAllTaskService;

    /**
     * 定时任务查询
     *
     * @param merchantDTO
     * @param criteria
     * @return
     */
    @PostMapping("/select")
    public CommonResult<PageInfo> select(MerchantDTO merchantDTO, @RequestBody ReissueAllCriteria criteria) {
        if (merchantDTO == null) {
            throw new ParameterException("请登录后访问");
        }
        criteria.setMerchantId(merchantDTO.getId());
        PageHelper.startPage(criteria.getPageNum(),criteria.getPageSize());
        List<ReissueAllDTO> list = reissueAllTaskService.select(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return new CommonResult<PageInfo>(CommonConstants.RETURN_SUCCESS,"查询成功",pageInfo);
    }

    /**
     *@param merchantDTO
     * @param criteria
     * @return
     */
    @PostMapping("/del")
    public CommonResult delReissueAll(MerchantDTO merchantDTO, @RequestBody ReissueAllCriteria criteria) {
        ReissueAllTask reissueAllTask=new ReissueAllTask();
        reissueAllTask.setMerchantId(merchantDTO.getId());
        reissueAllTask.setId(criteria.getId());
        reissueAllTaskService.delReissueAllTask(reissueAllTask);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS,"删除成功","");
    }
}
